package com.bootdo.market.controller;

import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.market.domain.ThirdSdkAdvunionAdvpositionStatisticsDO;
import com.bootdo.market.service.ThirdSdkAdvunionAdvpositionStatisticsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 变现方联盟广告展现统计
 *
 * @author jinse
 * @email market@jinse.com
 * @date 2019-05-13 13:00:27
 */

@Controller
@RequestMapping("/market/thirdSdkAdvunionAdvpositionStatistics")
public class ThirdSdkAdvunionAdvpositionStatisticsController {
    @Autowired
    private ThirdSdkAdvunionAdvpositionStatisticsService thirdSdkAdvunionAdvpositionStatisticsService;

    @GetMapping()
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionStatistics:thirdSdkAdvunionAdvpositionStatistics")
    String ThirdSdkAdvunionAdvpositionStatistics() {
        return "market/thirdSdkAdvunionAdvpositionStatistics/thirdSdkAdvunionAdvpositionStatistics";
    }

    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionStatistics:thirdSdkAdvunionAdvpositionStatistics")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<ThirdSdkAdvunionAdvpositionStatisticsDO> thirdSdkAdvunionAdvpositionStatisticsList = thirdSdkAdvunionAdvpositionStatisticsService.list(query);
        int total = thirdSdkAdvunionAdvpositionStatisticsService.count(query);
        PageUtils pageUtils = new PageUtils(thirdSdkAdvunionAdvpositionStatisticsList, total);
        return pageUtils;
       /* List<Map<String, String>> list = new ArrayList<>();
        //查询列表数据
        List<QueriedLog> logs = AliyunLogUtil.queryByPage_airmboll(0, 100000, "2019-06-11");
        logs.stream().forEach(queriedLog -> {
            Map<String, String> map = new HashMap<>();
            queriedLog.GetLogItem().mContents.stream().forEach(logContent -> {
                map.put(logContent.GetKey(), logContent.GetValue());
            });
            list.add(map);
        });*/
    }

    @GetMapping("/add")
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionStatistics:add")
    String add() {
        return "market/thirdSdkAdvunionAdvpositionStatistics/add";
    }

    @GetMapping("/edit/{id}")
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionStatistics:edit")
    String edit(@PathVariable("id") Integer id, Model model) {
        ThirdSdkAdvunionAdvpositionStatisticsDO thirdSdkAdvunionAdvpositionStatistics = thirdSdkAdvunionAdvpositionStatisticsService.get(id);
        model.addAttribute("thirdSdkAdvunionAdvpositionStatistics", thirdSdkAdvunionAdvpositionStatistics);
        return "market/thirdSdkAdvunionAdvpositionStatistics/edit";
    }

    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionStatistics:add")
    public R save(ThirdSdkAdvunionAdvpositionStatisticsDO thirdSdkAdvunionAdvpositionStatistics) {
        if (thirdSdkAdvunionAdvpositionStatisticsService.save(thirdSdkAdvunionAdvpositionStatistics) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionStatistics:edit")
    public R update(ThirdSdkAdvunionAdvpositionStatisticsDO thirdSdkAdvunionAdvpositionStatistics) {
        thirdSdkAdvunionAdvpositionStatisticsService.update(thirdSdkAdvunionAdvpositionStatistics);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionStatistics:remove")
    public R remove(Integer id) {
        if (thirdSdkAdvunionAdvpositionStatisticsService.remove(id) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("market:thirdSdkAdvunionAdvpositionStatistics:batchRemove")
    public R remove(@RequestParam("ids[]") Integer[] ids) {
        thirdSdkAdvunionAdvpositionStatisticsService.batchRemove(ids);
        return R.ok();
    }

}
